//
//  UILabel+Extension.m
//  Practice
//
//  Created by yons on 13.8.20.
//  Copyright © 2020 yons. All rights reserved.
//

#import "UILabel+Extension.h"

@implementation UILabel (Extension)

/// 显示背景颜色
/// @param backgroundColor 背景色
+ (UILabel *)labelWithBackgroundColor:(UIColor *)backgroundColor {
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = backgroundColor;
    return label;
}

/// 文本色+文本大小+字重(类方法)
/// @param textColor 文本色
/// @param size 文本大小
/// @param weight 字重
+ (UILabel *)labelWithTextColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight {
    UILabel *label = [[UILabel alloc] init];
    label.textColor = textColor;
    label.font = [UIFont systemFontOfSize:size weight:weight];
    return label;
}

/// 文本色+文本大小+字重+target+方法(类方法)
/// @param textColor 文本色
/// @param size 文本大小
/// @param weight 字重
/// @param target target
/// @param action 方法
+ (UILabel *)labelWithTextColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight target:(nullable id)target action:(nullable SEL)action {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight];
    label.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
    [label addGestureRecognizer:tapGesture];
    return label;
}

/// 文本颜色+文本大小+字重+圆角半径(类方法)
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 字重
/// @param radius 圆角
+ (UILabel *)labelWithTextColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight];
    label.userInteractionEnabled = YES;
    label.layer.cornerRadius = radius;
    label.clipsToBounds = YES;
    return label;
}

/// 文本颜色+文本大小+字重+圆角半径+target+方法((类方法)
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 字重
/// @param radius 圆角
/// @param target target
/// @param action 方法
+ (UILabel *)labelWithTextColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius target:(nullable id)target action:(nullable SEL)action {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight target:target action:action];
    label.userInteractionEnabled = YES;
    label.layer.cornerRadius = radius;
    label.clipsToBounds = YES;
    return label;
}

/// 文本+文本颜色+文本大小+字重+圆角半径+边框宽度+边框颜色(类方法)
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 字重
/// @param radius 圆角
/// @param borderWidth 边框宽度
/// @param borderColor 边框颜色
+ (UILabel *)labelWithTextColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight radius:radius];
    label.layer.borderWidth = borderWidth;
    label.layer.borderColor = borderColor.CGColor;
    return label;
}

/// 文本+文本颜色+文本大小+字重+圆角半径+边框宽度+边框颜色+target+方法(类方法)
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 字重
/// @param radius 圆角
/// @param borderWidth 边框宽度
/// @param borderColor 边框颜色
/// @param target target
/// @param action 方法
+ (UILabel *)labelWithTextColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor target:(nullable id)target action:(nullable SEL)action {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight radius:radius target:target action:action];
    label.layer.borderWidth = borderWidth;
    label.layer.borderColor = borderColor.CGColor;
    return label;
}

/// 文本+文本颜色+大小+字重(类方法)
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 文本weight
+ (UILabel *)labelWithText:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight];
    label.text = text;
    return label;
}

/// 文本+文本颜色+大小+字重+target+方法(类方法)
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 文本weight
/// @param target target
/// @param action 方法
+ (UILabel *)labelWithText:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight target:(nullable id)target action:(nullable SEL)action {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight target:target action:action];
    label.text = text;
    return label;
}

/// 文本+文本颜色+文本大小+字重+圆角半径(类方法)
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 字重
/// @param radius 圆角
+ (UILabel *)labelWithText:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight radius:radius];
    label.text = text;
    return label;
}

/// 文本+文本颜色+文本大小+字重+圆角半径+target+方法(类方法)
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 字重
/// @param radius 圆角
/// @param target target
/// @param action 方法
+ (UILabel *)labelWithText:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius target:(nullable id)target action:(nullable SEL)action {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight radius:radius target:target action:action];
    label.text = text;
    return label;
}

/// 文本+文本颜色+文本大小+字重+圆角半径+边框宽度+边框颜色(类方法)
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 字重
/// @param radius 圆角
/// @param borderWidth 边框宽度
/// @param borderColor 边框颜色
+ (UILabel *)labelWithText:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight radius:radius borderWidth:borderWidth borderColor:borderColor];
       label.text = text;
       return label;
}

/// 文本+文本颜色+文本大小+字重+圆角半径+边框宽度+边框颜色+target+方法(类方法)
/// @param text 文本
/// @param textColor 文本颜色
/// @param size 文本大小
/// @param weight 字重
/// @param radius 圆角
/// @param borderWidth 边框宽度
/// @param borderColor 边框颜色
/// @param target target
/// @param action 方法
+ (UILabel *)labelWithText:(NSString *)text textColor:(UIColor *)textColor fontSize:(CGFloat)size weight:(UIFontWeight)weight radius:(CGFloat)radius borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor target:(nullable id)target action:(nullable SEL)action {
    UILabel *label = [self labelWithTextColor:textColor fontSize:size weight:weight radius:radius borderWidth:borderWidth borderColor:borderColor target:target action:action];
    label.text = text;
    return label;
}

/// 添加点击方法
/// @param target target
/// @param action 方法
- (void)addTarget:(nullable id)target action:(nullable SEL)action {
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
    self.userInteractionEnabled = YES;
    [self addGestureRecognizer:tapGesture];
}

@end
